﻿@{
}

<section class="container-fluid m15_t">
    <div class="data-wrap case">
        <form class="form-inline" id="formSearch">
            <div class="data-tool clearfix">
                <div class="pull-left form-inline ">
                    <a class="btn btn-default btn-sm export m10_l" href="javascript:void(0)" data-title="导出">导出</a>
                    <div class="input-group input-group-sm">
                        <div class="input-sm"><input name="autoRefresh" type="checkbox" title="10秒自动刷新" /> <label id="time" class="wd125 gettext">10秒自动刷新</label></div>
                    </div>
                </div>
                <div class="pull-right">
                    <div class="input-group input-group-sm">
                        <label class="input-group-addon m5_l gettext">商户：</label>
                        <select name="merchantId" class="form-control">
                            <option value="">请选择</option>
                            @{
                                foreach (var item in (List<EC.Entity.Response.Merchant.MerchantResponse>)ViewBag.Merchants)
                                {
                                    <option value="@(item.Id)">@(item.Name)</option>
                                }
                            }
                        </select>
                    </div>
                    <div class="input-group input-group-sm">
                        <label class="input-group-addon m5_l gettext">支付状态：</label>
                        <select class="form-control gettext" name="paymentStatus">
                            <option value="">请选择</option>
                            <option value="1">未支付</option>
                            <option value="2">支付成功</option>
                            <option value="3">付款失败</option>
                            <option value="4">付款中</option>
                            <option value="100">未支付或付款中</option>
                        </select>
                    </div>
                    <div class="input-group input-group-sm">
                        <label class="input-group-addon m5_l">商户订单号：</label>
                        <input class="form-control" name="merchantOrderNo" type="text" autocomplete="off">
                    </div>
                    <div class="input-group input-group-sm">
                        <label class="input-group-addon m5_l">操作人：</label>
                        <input class="form-control wd120" name="handBy" type="text" autocomplete="off">
                    </div>
                    <button id="today" class="btn btn-default btn-sm gettext" type="button">今天</button>
                    <button id="yesterday" class="btn btn-default btn-sm gettext" type="button">昨天</button>
                    <button id="month" class="btn btn-default btn-sm gettext" type="button">本月</button>
                    <button type="button" class="btn btn-default btn-sm gettext" id="AdvSearch">高级搜索</button>

                </div>
            </div>
            <!--一高级搜索开始-->
            <div class="AdvSearch">
                <div class="AdvSearchcom collapse">
                    <table>
                        <tbody>
                            <tr>
                                <td class="gettext">通知状态：</td>
                                <td>
                                    <select class="form-control gettext" name="noticeStatus">
                                        <option value="">请选择</option>
                                        <option value="1">未通知</option>
                                        <option value="2">通知成功</option>
                                        <option value="3">通知失败</option>
                                    </select>
                                </td>
                                <td class="gettext"></td>
                                <td class="gettext"></td>
                            </tr>
                            <tr>
                                <td class="gettext">创建时间：</td>
                                <td rowspan="3">
                                    <input id="d421" class="Wdate wd175" name="startTime" type="text" value="@(ViewBag.StartTime)" onfocus="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss',maxDate:'%y-%M-%d'})" autocomplete="off" />
                                    -
                                    <input id="d422" class="Wdate wd175 m5_l" name="endTime" type="text" value="@(ViewBag.EndTime)" onfocus="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss',minDate:'#F{$dp.$D(\'d421\')}'})" autocomplete="off" />
                                </td>
                            </tr>
                        </tbody>
                    </table>
                    <div class="AdvSearchfooter t_c">
                        <button id="search" class="btn btn-default btn-sm gettext" type="button">立即搜索</button>
                        <button id="cancel" data-dismiss="modal" class="btn btn-default btn-sm gettext" type="button">取消</button>
                    </div>
                </div>
            </div>
        </form>


        <div class="data-easyui data-scroll">
            <div class="data-view">
                <div class="data-div-view table-responsive">
                    <table class="table" id="pager"></table>
                </div>
            </div>
        </div>
    </div>
</section>
<style type="text/css">
    .datagrid-cell, .datagrid-cell-group, .datagrid-header-rownumber, .datagrid-cell-rownumber {
        margin: 0;
        padding: 0 4px;
        white-space: nowrap;
        word-wrap: normal;
        overflow: hidden;
        height: 35px;
        line-height: 35px;
        font-size: 13px;
    }
</style>
@section footerScript{
    <script src="~/js/clipboard.min.js"></script>
    <script type="text/javascript">

        var pageSize = 20;
        var autoRefresh = $("input[name='autoRefresh']");

        $(function () {
            FlashPay.UI.DataAutoHeight();

            doSearch();

            $("#btnSearch").click(function () {
                doSearch();
            });

            $(autoRefresh).change(function () {
                wait = 10;
                time();
            });

            FlashPay.UI.Triggerbox({
                btnAdvSearch: '#AdvSearch',
                searchCallBack: function () {
                    window.currentPage = null;
                    doSearch();
                },
                cancelCallBack: function () {

                }
            });

            var clipboard = new Clipboard('.copy');
            clipboard.on('success', function (e) {
                FlashPay.UI.Tip_success("复制成功");
            });
            clipboard.on('error', function (e) {
                alert("您的浏览器可能不支持，请手动复制.")
            });

            $("#today").click(function () {
                $("input[name='startTime']").val('@(ViewBag.StartTime)');
                $("input[name='endTime']").val('@(ViewBag.EndTime)');

                doSearch();
            });

            $("#yesterday").click(function () {
                $("input[name='startTime']").val('@(ViewBag.YesterdayStartTime)');
                $("input[name='endTime']").val('@(ViewBag.YesterdayEndTime)');

                doSearch();
            });

            $("#month").click(function () {
                $("input[name='startTime']").val('@(ViewBag.MonthStartTime)');
                $("input[name='endTime']").val('@(ViewBag.MonthEndTime)');

                doSearch();
            });

            $(".export").click(function () {
                FlashPay.UI.Confirm({
                    content: "下载代付记录需要花费大量时间,确认要下载吗？",
                    ok: function () {

                        var cover = FlashPay.UI.Mask({
                            obj: $("body"),
                            opacity: 0.5
                        });

                        var query = $("#formSearch").serializeJSON();

                        FlashPay.Util.Ajax({
                            url: '/Paymentrecord/PaymentRecordExport',
                            type: 'POST',
                            data: { query: query },
                            success: function (response) {
                                if (response.success) {
                                    cover.Remove();
                                    if (response.rows != null && response.rows.length > 0) {
                                        var body = '<table>';

                                        body += '<tr>';
                                        body += '<td>订单号</td>';
                                        body += '<td>商户订单号</td>';
                                        body += '<td>代付金额</td>';
                                        body += '<td>手续费</td>';
                                        body += '<td>银行名称</td>';
                                        body += '<td>姓名</td>';
                                        body += '<td>卡号</td>';
                                        body += '<td>付款时间</td>';
                                        body += '<td>支付状态</td>';
                                        body += '<td>通知状态</td>';
                                        body += '<td>最后通知时间</td>';
                                        body += '<td>备注</td>';
                                        body += '<td>下单时间</td>';
                                        body += '<td>操作人</td>';
                                        body += '<td>操作时间</td>';
                                        body += '</tr>';


                                        $.each(response.rows, function (i, item) {

                                            var paymentStatusContent = '';

                                            if (item.paymentStatus == 1) {
                                                paymentStatusContent += '<span class="bold">未审核</span>';
                                            } else if (item.paymentStatus == 2) {
                                                paymentStatusContent = '<span class="green bold">付款成功</span>';
                                            } else if (item.paymentStatus == 3) {
                                                paymentStatusContent = '<span class="red bold">付款失败</span>';
                                            } else if (item.paymentStatus == 4) {
                                                paymentStatusContent = '<span class="bold">付款中</span>';
                                            } else if (item.paymentStatus == 5) {
                                                paymentStatusContent = '<span class="bold">取消付款</span>';
                                            }

                                            var noticeStatusContent = "";

                                            if (item.noticeStatus == 1) {
                                                noticeStatusContent = '<span class="bold">未通知</span>';
                                            } else if (item.noticeStatus == 2) {
                                                noticeStatusContent = '<span class="green bold">通知成功</span>';
                                            } else if (item.noticeStatus == 3) {
                                                noticeStatusContent = "<span class='red bold' title='{0}'>通知失败</span>".format(item.noticeFail);
                                            } else if (item.noticeStatus == 4) {
                                                noticeStatusContent = '<span class="bold">通知中</span>';
                                            }

                                            //withdrawalBankName withdrawalCardName withdrawalCardNumber _PaymentDate
                                            //paymentStatus noticeStatus _NoticeLastTime remark _CreatedDate
                                            body += '<tr>';
                                            body += '<td>' + item._Id + '</td>';
                                            body += '<td>' + item.merchantOrderNo + '</td>';
                                            body += '<td>' + item._WithdrawalAmount + '</td>';
                                            body += '<td>' + item._WithdrawalFee + '</td>';
                                            body += '<td>' + item.withdrawalBankName + '</td>';
                                            body += '<td>' + item.withdrawalCardName + '</td>';
                                            body += '<td>' + item.withdrawalCardNumber + '</td>';
                                            body += '<td>' + item._PaymentDate + '</td>';
                                            body += '<td>' + paymentStatusContent + '</td>';
                                            body += '<td>' + noticeStatusContent + '</td>';
                                            body += '<td>' + item._NoticeLastTime + '</td>';
                                            body += '<td>' + item.remark + '</td>';
                                            body += '<td>' + item._CreatedDate + '</td>';
                                            body += '<td>' + item._HandBy + '</td>';
                                            body += '<td>' + item._HandTime + '</td>';
                                            body += '</tr>';
                                        });

                                        body += '</table>';

                                        var excelFile = "<html xmlns:o='urn:schemas-microsoft-com:office:office' xmlns:x='urn:schemas-microsoft-com:office:excel' xmlns='http://www.w3.org/TR/REC-html40'>";
                                        excelFile += '<meta http-equiv="content-type" content="application/vnd.ms-excel; charset=UTF-8">';
                                        //excelFile += '<meta http-equiv="content-type" content="application/vnd.ms-excel';
                                        //excelFile += '; charset=UTF-8">';
                                        excelFile += "<head>";
                                        excelFile += "<!--[if gte mso 9]>";
                                        excelFile += "<xml>";
                                        excelFile += "<x:ExcelWorkbook>";
                                        excelFile += "<x:ExcelWorksheets>";
                                        excelFile += "<x:ExcelWorksheet>";
                                        excelFile += "<x:Name>";
                                        excelFile += "Sheet1";
                                        excelFile += "</x:Name>";
                                        excelFile += "<x:WorksheetOptions>";
                                        excelFile += "<x:DisplayGridlines/>";
                                        excelFile += "</x:WorksheetOptions>";
                                        excelFile += "</x:ExcelWorksheet>";
                                        excelFile += "</x:ExcelWorksheets>";
                                        excelFile += "</x:ExcelWorkbook>";
                                        excelFile += "</xml>";
                                        excelFile += "<![endif]-->";
                                        excelFile += "</head>";
                                        excelFile += "<body>";
                                        excelFile += body;
                                        excelFile += "</body>";
                                        excelFile += "</html>";

                                        var uri = window.URL.createObjectURL(new Blob([excelFile], { type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' }));//'data:application/vnd.ms-excel;charset=utf-8,' + encodeURIComponent(excelFile);
                                        var link = document.createElement("a");
                                        link.href = uri;

                                        link.style = "visibility:hidden";
                                        link.download = response.statusCode + ".xls";

                                        document.body.appendChild(link);
                                        link.click();
                                        document.body.removeChild(link);
                                    }
                                    else {
                                        cover.Remove();
                                        FlashPay.UI.Tip_short_warning("暂无记录");
                                    }

                                } else {
                                    cover.Remove();
                                    FlashPay.UI.Tip_short_warning("操作失败！" + response.errorMessage);
                                }
                            },
                            error: function (json) {
                                cover.Remove();
                                FlashPay.UI.Tip_warning("操作失败！请查看网络，请重试。");
                            }
                        });
                    }
                });
            })
        });

        function audit() {
            $("select[name='paymentStatus']").val(100);
            doSearch();
        }

        //倒时计
        function time() {

            var language = FlashPay.Util.Language();

            var obj = document.getElementById("time");

            var isauto = $(autoRefresh).is(':checked');
            if (!isauto) {

                obj.innerText = "10 秒自动刷新";

                return false;
            }

            if (wait == 0) {
                obj.innerText = "10秒自动刷新";

                wait = 10;

                if (isauto) {
                    setTimeout(function () { time(); }, 1000);
                }

                FlashPay.UI.DoSearch();
            } else {
                obj.innerText = wait + "秒自动刷新";
                wait--;
                setTimeout(function () { time(); }, 1000);
            }
        }

        function Tip_success(word) {
            FlashPay.UI.Tip_success(word);
        }

        function getParams() {
            var params = $("#formSearch").serializeJSON();
            return params;
        }

        function doSearch() {
            var frozenColumns = [[
                {
                    field: '_Id', title: "订单号", width: 100,
                    align: 'left',
                    formatter: function (val, item) {
                        if (!FlashPay.Util.isNullOrEmptySpance(val)) {
                            return '{0}'.format(val);
                        } else {
                            return "";
                        }
                    }
                },
                { field: 'merchantName', title: "商户", width: 100, align: 'left' },
                {
                    field: 'merchantOrderNo',
                    title: "商户订单号",
                    width: 150,
                    align: 'left',
                    formatter: function (val, item) {

                        if (!FlashPay.Util.isNullOrEmptySpance(val)) {

                            var result = '<span class="f_l">{0}</span>'.format(val);;

                            return result;

                        } else {
                            return "";
                        }

                    }
                }
            ]];
            var columns = [[
                {
                    field: 'proxyMerchantName',
                    title: '组',
                    width: 75,
                    align: 'center',
                    formatter: function (val, item) {
                        if (!FlashPay.Util.isNullOrEmptySpance(val)) {
                            return '<span class="">{0}</span>'.format(val);
                        } else {
                            return "";
                        }
                    }
                },
                {
                    field: '_WithdrawalAmount',
                    title: '金额',
                    width: 120,
                    align: 'left',
                    formatter: function (val, item) {
                        if (!FlashPay.Util.isNullOrEmptySpance(val)) {
                            return '<span class="f_l red bold">{0}</span><span class="f_r"><a class="copy" data-clipboard-text="{0}">复制</a></span>'.format(val);
                        } else {
                            return "";
                        }
                    }
                },
                {
                    field: '_WithdrawalFee',
                    title: '手续费',
                    width: 100,
                    align: 'right'
                },
                {
                    field: 'withdrawalBankName',
                    title: '银行名称',
                    width: 75,
                    align: 'left'
                },
                {
                    field: 'withdrawalCardName',
                    title: '姓名',
                    width: 120,
                    align: 'left',
                    formatter: function (val, item) {
                        if (!FlashPay.Util.isNullOrEmptySpance(val)) {
                            return '<span class="f_l">{0}</span><span class="f_r"><a class="copy" data-clipboard-text="{0}">复制</a></span>'.format(val);
                        } else {
                            return "";
                        }
                    }
                },
                {
                    field: 'withdrawalCardNumber',
                    title: '卡号',
                    width: 200,
                    align: 'left',
                    formatter: function (val, item) {
                        if (!FlashPay.Util.isNullOrEmptySpance(val)) {
                            return '<span class="f_l">{0}</span><span class="f_r"><a class="copy" data-clipboard-text="{0}">复制</a></span>'.format(val);
                        } else {
                            return "";
                        }
                    }
                },
                {
                    field: 'paymentStatus',
                    title: '支付状态',
                    width: 175,
                    align: 'left',
                    formatter: function (val, item) {
                        var result = '';

                        if (val == 1) {
                            result += '<span class="bold f_l">未审核</span>';
                            if (item.auditPermission == "PaymentRecord0002") {
                                result += ' <span class="f_r"><a class="btn btn-success btn-xs" data-confirm="确定要<span class=orange>审核</span>该订单？" data-succesFun="audit()" data-href="/PaymentRecord/Audit/{0}">审核</a></span>'.format(item.id);
                            }
                        } else if (val == 2) {
                            result = '<span class="green bold f_l">付款成功</span> ';
                            if (item.revokePermission == "PaymentRecord0005") {
                                result += '<span class="f_r"><a class="btn btn-danger btn-xs" data-modal="/PaymentRecord/Undo/{0}" data-title="确认失败" data-confirmname="确认失败" data-width="420" data-height="230"> 确认失败</a></span>'.format(item.id);
                            }
                        } else if (val == 3) {
                            result = '<span class="red bold">付款失败</span>';

                            if (item.cancelPermission == "PaymentRecord0004") {
                                result += ' <a class="btn btn-xs btn-warning" data-confirm="确定要<span class=orange>还原成功</span>该付款单？" data-succesFun="doSearch()" data-href="/PaymentRecord/ReturnSuccess?id={0}">还原成功</a>'.format(item.id);
                            }
                            
                        } else if (val == 4) {

                            result = '<span class="bold f_l">付款中</span>';
                            
                            result += ' <span class="f_r">'
                            if (item.cancelPermission == "PaymentRecord0004") {
                                result += ' <a class="btn btn-danger btn-xs" data-modal="/PaymentRecord/Undo/{0}" data-title="确认失败" data-confirmname="确认失败" data-width="420" data-height="230"> 确认失败</a> '.format(item.id);
                            }
                                
                            if (item.confirmPermission == "PaymentRecord0003") {
                                result += ' <a class="btn btn-success btn-xs" data-modal="/PaymentRecord/Confirm/{0}" data-title="确认打款" data-confirmname="确认付款" data-width="420" data-height="230"> 确认打款</a> '.format(item.id);
                            }

                            result += ' </span>'

                        } else if (val == 5) {
                            result = '<span class="bold">取消付款</span>';
                        } else if (val == 6) {
                            result = '<span class="bold">撤销</span>';
                        }

                        return result;
                    }
                },
                {
                    field: 'noticeStatus',
                    title: '通知状态',
                    width: 120,
                    align: 'left',
                    formatter: function (val, item) {
                        /**
                         * 1、未通知
                         * 2、通知成功
                         * 3、通知失败
                         * 4、通知中
                         * */
                        var result = "";

                        if (val == 1) {
                            result = '<span class="bold">未通知</span>';
                        } else if (val == 2) {
                            result = '<span class="green bold">通知成功</span>';
                        } else if (val == 3) {
                            result = "<span class='red bold' title='{0}'>通知失败</span>".format(item.noticeFail);
                            if (item.noticeTimes >= 5) {
                                result += ' <a class="btn btn-xs btn-warning" data-confirm="确定要<span class=orange>重置</span>该付款单？" data-succesFun="doSearch()" data-href="/PaymentRecord/Reset?id={0}">重置</a>'.format(item.id);
                            }
                        } else if (val == 4) {
                            result = '<span class="bold">通知中</span>';
                        } else if (val == 5) {
                            result = '<span class="bold">不通知</span>';
                        }

                        return result;
                    }
                },
                {
                    field: '_PaymentDate',
                    title: '付款时间',
                    width: 120,
                    align: 'left'
                },
                {
                    field: '_NoticeLastTime',
                    title: '最后通知时间',
                    width: 120,
                    align: 'left'
                },
                {
                    field: 'noticeTimes',
                    title: '通知次数',
                    width: 60,
                    align: 'left',
                    formatter: function (val, item) {

                        if (!FlashPay.Util.isNullOrEmptySpance(val)) {
                            return '{0}'.format(val);
                        } else {
                            return "";
                        }
                    }
                },
                {
                    field: '_HandTime',
                    title: '处理时间/操作人',
                    width: 200,
                    align: 'left',
                    formatter: function (val, item) {
                        if (!FlashPay.Util.isNullOrEmptySpance(val)) {
                            return '{0}/{1}'.format(item._HandTime, item._HandBy);
                        } else {
                            return "";
                        }
                    }
                },
                {
                    field: 'remark',
                    title: '备注',
                    width: 100,
                    align: 'left',
                    formatter: function (val, item) {
                        if (!FlashPay.Util.isNullOrEmptySpance(val)) {
                            return '{0}'.format(val);
                        } else {
                            return "";
                        }
                    }
                },
                {
                    field: '_CreatedDate',
                    title: '下单时间',
                    width: 120,
                    align: 'left'
                }
            ]];

            $("#pager").datagrid({
                fit: false,
                loadMsg: '数据加载中，请稍后……',
                method: "get",
                border: true,
                url: '/PaymentRecord/PaymentRecordQuery',
                queryParams: getParams(),
                pagination: true,
                pageSize: pageSize,
                pageList: [20],
                height: $(window).height() - 70,
                singleSelect: true,
                rownumbers: true,
                showFooter: true,
                idField: 'Id',
                onLoadSuccess: function () {
                    pageSize = $('#pager').datagrid('options').pageSize;
                },
                frozenColumns: frozenColumns,
                columns: columns
            });
        }
    </script>
}


